/* Copyright (C) 2002-2005 RealVNC Ltd.  All Rights Reserved.
 * 
 * This is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this software; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
 * USA.
 */

package vncviewer;

import java.awt.*;

class PasswdDialog extends vncviewer.Dialog {

  public PasswdDialog(String title, boolean userDisabled, boolean passwdDisabled) {
    super(true);
    setTitle(title);
    Panel p1 = new Panel();
    userLabel = new Label("Username:");
    p1.add(userLabel);
    userEntry = new TextField(30);
    userEntry.setEnabled(!userDisabled);
    userLabel.setEnabled(!userDisabled);
    p1.add(userEntry);
    add("Center", p1);

    Panel p2 = new Panel();
    passwdLabel = new Label("Password:");
    p2.add(passwdLabel);
    passwdEntry = new TextField(30);
    passwdEntry.setEchoChar('*');
    passwdEntry.setEnabled(!passwdDisabled);
    passwdLabel.setEnabled(!passwdDisabled);
    p2.add(passwdEntry);
    add("South", p2);

    pack();
  }

  synchronized public boolean action(Event event, Object arg) {
    if (event.target == userEntry) {
      if (passwdEntry.isEnabled())
        passwdEntry.requestFocus();
      else {
      	ok = true;
      	endDialog();
      }
    } else if (event.target == passwdEntry) {
      ok = true;
      endDialog();
    }
    return true;
  }

  Label userLabel;
  TextField userEntry;
  Label passwdLabel;
  TextField passwdEntry;
}
